from tools_algorithm import *


class Solution:
    def maximumSubarrayXor(
        self, nums: List[int], queries: List[List[int]]
    ) -> List[int]:
        n = len(nums)
        f = [[0] * n for _ in range(n)]
        x = [[0] * n for _ in range(n)]
        f[0] = nums
        x[0] = nums
        for i in range(1, n):
            for j in range(0, n - i):
                f[i][j] = f[i - 1][j] ^ f[i - 1][j + 1]
                x[i][j] = max(f[i][j], x[i - 1][j], x[i - 1][j + 1])
        ans = []
        for l, r in queries:
            ans.append(x[r - l][l])
        return ans


s = Solution()
print(s.maximumSubarrayXor(nums=[2, 8, 4, 32, 16, 1], queries=[[0, 2], [1, 4], [0, 5]]))
s = "abcdefghijk"  # fghij
a = list(s[:-3])


def f(a, b):
    x = list(a)
    for v in b:
        if v in x:
            x.pop(x.index(v))
        else:
            x.append(v)
    return "".join(x)


print(a)
while len(a) > 1:
    for i in range(len(a) - 1):
        a[i] = f(a[i], a[i + 1])
    a.pop()
    print(a)
print(a)


# c = []
# for _ in range(100):
#     c.append(random.randint(0, (1 << 15) - 1))
# q = []
# for _ in range(100):
#     q.append([a := random.randint(0, 99), random.randint(a, 99)])
# print(c)
# print(q)
